//获取合约的地址
import {reqweb3} from './reqweb3.js'

function getContract(url,addr,abi,account){
  let paramList = []
  // let param1 = 'selectByName Trade'    //目前Trade无法搜出，先用FileShare
  let param1 = 'selectByName FileShare'
  let param2 = 'selectByName Witness'
  let param3 = 'selectByName Assets'
  let myaccount = {address: account.address}
  let conparam = {
    req: url,
    addr: addr,
    abi: abi,
  }
  paramList.push(reqweb3(param1,myaccount,conparam))
  paramList.push(reqweb3(param2,myaccount,conparam))
  paramList.push(reqweb3(param3,myaccount,conparam))
  // console.log('最终返回数组',paramList)

  return Promise.all(paramList).then((values) => {
    let mysol = []
    values.forEach(item=>{          //
      let status = item.status;
      if(status!=='0x0'){
        return new Promise((resolve,reject)=>{
          reject([])
        })
      }
      let result = item.output.result;
      let resultJson = JSON.parse(result)
      let contractArr = resultJson[resultJson.length - 1]
      mysol.push(contractArr)
    })
    return new Promise((resolve,reject)=>{
      resolve(mysol)
    })   
  })
}

export {getContract}
